<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/11/25 0025
 * Time: 9:19
 */
namespace app\api\controller;

use app\api\model\Api;
use app\api\model\JWT;
use think\App;
use think\Controller;
use think\helper\Hash;
use think\Db;

/**
 * @title 图片上传
 * @description 接口说明
 */
class Toget extends Api
{
    /**
     * @title 图片上传
     * @description 接口说明
     * @author 开发者
     * @url /api/toget/upload
     * @method post
     *
     * @param name:file type:string require:1 default:1 other: desc:图片
     *
     */
    public function upload()
    {
        $uid = 0;
        $file = $this->request->file();
        if (!empty($file)) {
            $rs = post_upload_one($uid, 'file');
        } else {
            return $this->ajaxReturn(1, '上传错误');
        }
        if ($rs['code'] == 0) {
            $data['id'] = $rs['msg'];
            $data['url'] = get_file_path($data['id']);
            return $this->ajaxReturn(0, '成功',$data);
        } else {
            return $this->ajaxReturn(1, '上传失败');
        }
    }
    /**
     * @title 多图上传
     * @description 接口说明
     * @author 开发者
     * @url /api/toget/uploads
     * @method post
     *
     * @param name:file type:string require:1 default:1 other: desc:图片
     *
     */
    public function uploads(){
        $uid = 0;
        $file = $this->request->file();

        if (!empty($file)) {
            $rs = post_uploads($uid, 'file');
        } else {
            return $this->ajaxReturn(1, '上传错误');
        }
        if ($rs['code'] == 200) {
            return $this->ajaxReturn(0, '成功',$rs['msg']);
        }
        return $this->ajaxReturn(1, '上传错误');
    }

    function http_curl($url)
    {
        $curl = curl_init();//初始化
        curl_setopt($curl,CURLOPT_URL,$url);//设置抓取的url   
        curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);// https请求 不验证证书和hosts   
        curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,false);
        curl_setopt($curl,CURLOPT_HEADER,0);//   设置头文件的信息作为数据流输出   设置为1 的时候，会把HTTP信息打印出来  不要http header 加快效率   
        curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);//设置获取的信息以文件流的形式返回，而不是直接输出。 如果设置是0，打印信息就是true   
        $data = curl_exec($curl);//执行命令   
        $result = json_decode($data,true);
        if ($data == false) {
            echo "Curl Error:" . curl_error($curl);exit();
        }
        curl_close($curl);//关闭URL请求   
        return $result;
    }
    /**
     * @title 下载接口
     * @description 接口说明
     * @author 开发者
     * @url /api/toget/load
     * @method post
     *
     * @return url:下载链接
     */
    public function load(){
        $url = '';
        $data['url'] = $url;
        return $this->ajaxReturn(0,'成功',$data);
    }
}